//
//  RewardListCell.m
//  Base_App
//
//  Created by Yutian Duan on 2019/6/4.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "RewardListCell.h"

@implementation RewardListCell

- (void)awakeFromNib {
  [super awakeFromNib];
  // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  [super setSelected:selected animated:animated];
  
  // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if (self) {
    [self createViews];
  }
  return self;
}

- (void)createViews {
  ///!
  _bgView = [[UIView alloc] init];
  _bgView.backgroundColor = HEXCOLOR(0xfefffe);
  _bgView.layer.masksToBounds = YES;
  _bgView.layer.cornerRadius = 8.0f;
  [self.contentView addSubview:_bgView];
  
  _coverImageView = [[UIImageView alloc] init];
  [_bgView addSubview:_coverImageView];
  
  _titleLabel = [[UILabel alloc] init];
  [_bgView addSubview:_titleLabel];
  
  //!
  _noteImageView = [[UIImageView alloc] init];
  _noteImageView.image = [UIImage imageNamed:@"Home_timeLimit"];
  [_bgView addSubview:_noteImageView];
  
  _noteLabel = [[UILabel alloc] init];
  _noteLabel.font = [UIFont systemFontOfSize:14];
  _noteLabel.text = [NSString stringWithFormat:@"%@！",YTLocalizedString(@"投保e客户特享受全城至低价格")];
  _noteLabel.textAlignment = NSTextAlignmentLeft;
  _noteLabel.textColor = DEF_GRAY;
  [_bgView addSubview:_noteLabel];
  
  ///!
  _priceView = [[UIView alloc] init];
  //  _priceView.backgroundColor = [UIColor redColor];
  [_bgView addSubview:_priceView];
  
  _priceLabel = [[UILabel alloc] init];
  _priceLabel.font = [UIFont systemFontOfSize:15];
  _priceLabel.textAlignment = NSTextAlignmentCenter;
  _priceLabel.textColor = DEF_GRAY;
  [_priceView addSubview:_priceLabel];
  
  _exchangeButton = [[UIButton alloc] init];
  [_exchangeButton setTitle:YTLocalizedString(@"立即兑换") forState:UIControlStateNormal];
  [_exchangeButton setTitleColor:DEF_GRAY forState:UIControlStateNormal];
  _exchangeButton.titleLabel.font = [UIFont systemFontOfSize:12];
  [_priceView addSubview:_exchangeButton];
  
  
  [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.mas_equalTo(self.contentView).offset(20);
    make.top.mas_equalTo(self.contentView.mas_top);
    make.bottom.mas_equalTo(self.contentView).offset(-10);
    make.trailing.mas_equalTo(self.contentView).offset(-20);
  }];
  
  [_coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.trailing.top.mas_equalTo(self.bgView);
    make.height.mas_equalTo(self.bgView.mas_width).multipliedBy(IMAGEPRO);
  }];
  
  [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.mas_equalTo(self.coverImageView.mas_leading).offset(10);
    make.top.mas_equalTo(self.coverImageView.mas_bottom);
    make.height.mas_equalTo(@30);
    make.trailing.mas_equalTo(self.priceView.mas_leading);
  }];
  
  [_noteImageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.mas_equalTo(self.titleLabel.mas_leading);
    make.top.mas_equalTo(self.titleLabel.mas_bottom);
    make.width.mas_equalTo(@40);
    make.height.mas_equalTo(@20);
  }];
  
  
  [_noteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.height.top.mas_equalTo(self.noteImageView);
    make.leading.mas_equalTo(self.noteImageView.mas_trailing).offset(10);
    make.trailing.mas_equalTo(self.titleLabel.mas_trailing);
  }];
  
  
  ///----
  [_priceView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.trailing.mas_equalTo(self.bgView.mas_trailing);
    make.top.mas_equalTo(self.coverImageView.mas_bottom);
    make.bottom.mas_equalTo(self.bgView.mas_bottom);
    make.width.mas_equalTo(@100);
  }];
  
  [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.trailing.top.mas_equalTo(self.priceView);
    make.bottom.mas_equalTo(self.priceView.mas_centerY);
  }];
  
  [_exchangeButton mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.trailing.bottom.mas_equalTo(self.priceView);
    make.top.mas_equalTo(self.priceLabel.mas_bottom);
  }];
  
}

- (void)setModel:(RewardListModel *)model {
  _model = model;
  [self setupModel];
}

- (void)setupModel {
  
  _coverImageView.image = [UIImage imageNamed:@"home_最新消息_01"];
  _titleLabel.text = @"8折汽车美容";
  _noteImageView.image = [UIImage imageNamed:@"Reward_car"];
  _noteLabel.text = YTLocalizedString(@"著数及入油记录一览无遗");
  
  _priceLabel.text = @"7,500pt.";
  
  
}


@end

